package com.asiainfo.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.asiainfo.bean.LiangBean;
import com.asiainfo.bean.UserSessionBean;
import com.asiainfo.dao.BaseDao;
import com.asiainfo.util.SessionInfoUtil;

@Controller
@RequestMapping("/mobileController")
public class MobileController extends ModelAndView{
	
private Logger logger = LogManager.getLogger(this.getClass());
	
	/**
	 * 数据操作封装DAO
	 */
	@Autowired
	private BaseDao dao;
	
	/**
	 * 方法描述：跳转到靓号列表页面
	 * 
	 * return 靓号列表页面页面Model
	 */
	@RequestMapping("/liangChoiceView.do")
	public ModelAndView liangList() {
		this.setViewName("business/liangChoice");
		return this;	
	}
	
	/*
	 * 获得所有靓号
	 * 
	 * http://localhost:8080/zsywzs/mobileController/liangChoice.do 
	 * */
	@RequestMapping(value = "/liangChoice.do",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject liangChoice(@RequestParam("remark") String remark, 
			HttpServletRequest request) throws Exception {
		JSONObject retMsg = new JSONObject();
		
		UserSessionBean userSessionBean = SessionInfoUtil.getUserSessBean(request.getSession());
		List<LiangBean> liangList= new ArrayList<LiangBean>();
//		String remark = request.getParameter("remark");
		String thisremark = null;
		
		if(null == userSessionBean)
		{
			logger.error("session 为空时需求重新登录。");
			retMsg.put("flag", false);
		}else
		{
			//获得所有可选靓号
			liangList =this.dao.getDAO().selectList(
						"LiangController.liangShow",remark);
			LiangBean bean = liangList.get(2);
			thisremark = bean.getTel_remark();
 			retMsg.put("flag", true);
		}
		
		this.addObject("liangList",liangList);
		this.addObject("thisremark",thisremark);
		
		return retMsg;
	
	}
}
